package com.xbongbong.saas.enums;

import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.saas.enums.business.ContactEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 只入数据库未入es枚举
 *
 * @Author: hongxiao
 * @date: 2021-11-15 21:54
 */
@Getter
public enum OnlyInsertDBEnum {
    // 联系人头像
    CONTACT_AVATAR(XbbRefTypeEnum.CONTACT.getCode(), ContactEnum.AVATAR.getAttr(), DistributorMarkEnum.OTHER.getCode()),
    ;

    private Integer businessType;

    private String attr;

    private Integer distributorMark;

    OnlyInsertDBEnum(Integer businessType, String attr, Integer distributorMark) {
        this.businessType = businessType;
        this.attr = attr;
        this.distributorMark = distributorMark;
    }

    public static List<OnlyInsertDBEnum> getByBusinessType(Integer businessType, Integer distributorMark) {
        List<OnlyInsertDBEnum> list = new ArrayList<>();
        for(OnlyInsertDBEnum onlyInsertDBEnum: values()) {
            if(Objects.equals(onlyInsertDBEnum.getBusinessType(), businessType)
                    && Objects.equals(onlyInsertDBEnum.getDistributorMark(), distributorMark)) {
                list.add(onlyInsertDBEnum);
            }
        }
        return list;
    }

    public static List<String> getAttrByBusinessType(Integer businessType, Integer distributorMark) {
        List<String> list = new ArrayList<>();
        for(OnlyInsertDBEnum onlyInsertDBEnum: values()) {
            if(Objects.equals(onlyInsertDBEnum.getBusinessType(),businessType)
                    && Objects.equals(onlyInsertDBEnum.getDistributorMark(), distributorMark)) {
                list.add(onlyInsertDBEnum.getAttr());
            }
        }
        return list;
    }

    public static boolean containBusinessType(Integer businessType, Integer distributorMark) {
        for(OnlyInsertDBEnum onlyInsertDBEnum: values()) {
            if(Objects.equals(onlyInsertDBEnum.getBusinessType(),businessType)
                    && Objects.equals(onlyInsertDBEnum.getDistributorMark(), distributorMark)) {
                return true;
            }
        }
        return false;
    }

    public static boolean containBusinessTypeAttr(Integer businessType, String attr, Integer distributorMark) {
        for(OnlyInsertDBEnum onlyInsertDBEnum: values()) {
            if(Objects.equals(onlyInsertDBEnum.getBusinessType(),businessType)
                    && Objects.equals(onlyInsertDBEnum.getAttr(), attr)
                    && Objects.equals(onlyInsertDBEnum.getDistributorMark(), distributorMark)) {
                return true;
            }
        }
        return false;
    }
}
